<template>
  <div id="app" ref='app'>
    <!-- <vue-header v-show='headerShow' :tipsFunText="tipsFunText"></vue-header> -->
    <router-view v-on:tipsFunFlag="tipsFunFlag"/>
    <!-- <vue-footer  v-if='footerShow'></vue-footer> -->
    <!-- <concatUs></concatUs> -->
  </div>
</template>

<script>
import VueHeader from "@/common/public/vueHeader";
import VueFooter from "@/common/public/vueFooter";
import concatUs from "@/common/public/concatUs";
import { mapGetters, mapActions } from "vuex";
import Vue from 'vue'

export default {
  name: "App",
  data () {
    return {
      tipsFunText:0, //平台公告弹窗
      params:{
          token:"",
        }
    }
  },
  components: {
    concatUs,
    VueHeader,
    VueFooter
  },
  mounted() {
    //获取路由
    var path = this.$route.path.substring(1);
    //全局msg配置
    this.$Message.config({
        duration: 2,
        top: 200,
    });
    // if(localStorage.getItem("token") == null){
    //   return
    // }else{
    //   this.params.token = localStorage.getItem("token")
    //   this.$http.post(this.urlRequest + '?m=api&c=account&a=index',this.params).then(res=>{
    //     this.$store.commit ("money_usable",res.data.money_usable)
    //     this.$store.commit ("money_freeze",res.data.money_freeze)
    //   })
    // }
    // this._showNavChane(path);

    
    this.$nextTick(()=>{
        console.log(document.querySelector('.concatUs'))
    })
  },
  computed: {
    ...mapGetters(['platformConfig', 'casinoSwitch', 'headerShow', 'footerShow'])
  },
  methods: {
    ...mapActions(['SET_ACCOUNT_DATA', 'SET_USER_INFO_DATA', 'SET_PLATFORM_CONFIG', 'SET_CASINO_SWITCH', 'HEADER_SHOW', 'HEADER_HIDE']),
    tipsFunFlag(bool) { //平台公告弹窗
      this.tipsFunText += bool;
    },
    setFaviconIcon() {
      let link = document.querySelector("link[rel*='icon']") || document.createElement('link');
      link.type = 'image/x-icon';
      link.rel = 'shortcut icon';
      link.href = this.platformConfig.favicon_ico;
      document.getElementsByTagName('head')[0].appendChild(link);
    },
    _getCasinoSwitch() { //真人娱乐开关
      this.$http.post(this.urlRequest +"?m=api&c=game&a=getIndexCasinoSW").then(res=>{
        if (res.data.status == 0) {
          this.SET_CASINO_SWITCH({
            obj: res.data.data
          });
        }
      })
    },
  },
  created () {
    this._getCasinoSwitch();
  //   window.onbeforeunload=function (){   
  //     localStorage.setItem('token','')
  // }
    if( localStorage.getItem("token")){
      // this.$store.dispatch('SET_USER_INFO_DATA')
      
      this.SET_USER_INFO_DATA({
        Obj:{}
      })
      this.SET_ACCOUNT_DATA({
        Obj:{}
      })
    }
  },
  watch: {
    platformConfig(obj) {
      if (obj.favicon_ico) {
        this.setFaviconIcon();
      }
    },
    $route(to) {
      // this._getCasinoSwitch();
      if(to.path=='/login' || to.path=='/reg'){
        this.$store.dispatch('HEADER_HIDE');
      }else{
        this.$store.dispatch('HEADER_SHOW')
        if (to.path=='/home') {
          if (!localStorage.getItem("token")) {
            // this.SET_USER_INFO({
            //   obj: {}
            // });
            this.SET_ACCOUNT_DATA({
              obj: {}
            });
            this.SET_ACCOUNT_DATA({
              Obj: {}
            });
          }
       } 
      }
      
    }
  }
};
</script>



// WEBPACK FOOTER //
// src/App.vue